package com.hamizhong.iflowers.web.action.admin.user;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.hamizhong.iflowers.service.IUserService;
import com.hamizhong.iflowers.utils.MyConstants;
import com.hamizhong.iflowers.utils.MyErrorMsgConstants;
import com.hamizhong.iflowers.web.base.MyBaseAjaxAction;
import com.hamizhong.iflowers.web.dto.IOPResultDto;
import com.hamizhong.iflowers.web.vo.AdminVO;
import com.hamizhong.iflowers.web.vo.IObjectVO;
import com.hamizhong.iflowers.web.vo.UserVO;

public class AjaxResetUserPasswordAction extends MyBaseAjaxAction {
	
	private IUserService iUserService;
	
	public IUserService getiUserService() {
		return iUserService;
	}
	public void setiUserService(IUserService iUserService) {
		this.iUserService = iUserService;
	}
	
	@Override
	protected JSONObject doRequest() {
		logger.info("...invoke...AjaxUpdateUserAction...");

		JSONObject jo = new JSONObject();
		JSONArray ja = new JSONArray();
		JSONObject jobj = null;
		
		AdminVO adminVO = (AdminVO) getSSN().getAttribute(MyConstants.IFLOWERS_LOGIN_ADMIN_VO);
		if(adminVO == null) {
			jo.put("msg", MyErrorMsgConstants.ERR_LOGIN_ADMIN);
			jo.put("result", MyConstants.AJAX_FAILED_LOGIN_ADMIN);
			return jo;
		}
		
		String userId = getRQ().getParameter("userId");
		
		UserVO userVO = new UserVO();
		userVO.setUserId(Integer.valueOf(userId));
		IOPResultDto<IObjectVO> resultDto = iUserService.updateUserPassword(userVO, MyConstants.IFLOWERS_RESET_USER_PASSWORD_VALUE, adminVO.getAdminId());
		if(resultDto.isSuccess()) {
			jo.put("result", MyConstants.AJAX_SUCCESS);
		}else {
			jo.put("msg", resultDto.getErrorMSG());
			jo.put("result", MyConstants.AJAX_FAILED_ALERT);
		}
		return jo;
	}

}
